<?php

namespace App\Http\Controllers;

use App\JkblWenben;
use Illuminate\Http\Request;

/**
 * Class JkblWenbenController
 * @package App\Http\Controllers
 */
class JkblWenbenController extends Controller
{
    /**
     * JkblWenbenController constructor.
     */
    public function __construct()
    {
        $this->middleware('auth');
    }

    /**
     * @param $type
     * @return $this
     */
    public function agreement($type)
    {
        $agreement = JkblWenben::select('id', 'title', 'content')->where('type', $type)->first();
        return view('agreement.agreement')->with(compact('agreement'));
    }

    /**
     * @param Request $request
     * @param JkblWenben $jkblWenben
     * @return \Illuminate\Http\JsonResponse
     */
    public function agreementEdit(Request $request, JkblWenben $jkblWenben)
    {
        $jkblWenben->title = $request->title;
        $jkblWenben->content = $request->contents;
        if (!$jkblWenben->save()) {
            return response()->json(error());
        }
        return response()->json(success());
    }

}
